import 'package:flutter/material.dart';
import '../data/CustomData.dart';

class MovieScroll extends StatelessWidget {
  final List scrolllist = new CustomData().scrolllist;
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 260,
      // 数据长度不固定
      child: ListView.builder(
        scrollDirection: Axis.horizontal,
        itemCount: scrolllist.length,
        // 返回值是一个组件  context默认的 
        itemBuilder: (BuildContext context, int index){
          return ScrollItem(item: scrolllist[index]);
        },
      ),
    );
  }
}

class ScrollItem extends StatelessWidget {

  ScrollItem({Key key,@required this.item}):super(key:key);
  final Map item;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 137.5,
      padding: EdgeInsets.only(left: 5, right: 5),
      child: Column(
        children: <Widget>[
          Container(
            height: 178.5,
            width: 127.5,
            child: Image(
              image: NetworkImage('${item["img"]}'),
              fit: BoxFit.cover,
            ),
          ),
          Text('${item["name"]}'),
          Text(
            '${item["dra"]}',
            overflow: TextOverflow.ellipsis,
            maxLines: 2,
            style: TextStyle(
              color: Colors.grey
            ),
          ),
        ],
      ),
    );
  }
}